package com.filefilter.file;

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * \* Created with IntelliJ IDEA.
 * \* Author: fly
 * \* Date: 2020/6/14
 * \* Time: 20:26
 * \* Description:  重写监听器
 * \
 */
@Component
public class FilterListener extends FileAlterationListenerAdaptor {
    @Override
    public void onStart(FileAlterationObserver observer) {
        System.out.println(Thread.currentThread().getName());
        System.out.println("观察文件变化任务启动");
    }

    @Override
    public void onDirectoryCreate(File directory) {
        System.out.println("创建文件夹" + directory);
        try {
            throw new NullPointerException("创建文件夹 为null");
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    @Override
    public void onDirectoryChange(File directory) {
        System.out.println("修改文件夹" + directory);

    }

    @Override
    public void onDirectoryDelete(File directory){

        System.out.println("删除文件夹 " + directory);


    }

    @Override
    public void onFileCreate(File file) {

        System.out.println("创建文件 " + file);


    }

    @Override
    public void onFileChange(File file) {
        System.out.println("修改文件 "+ file);

    }

    @Override
    public void onFileDelete(File file) {
        System.out.println("删除文件 " + file);

    }

    @Override
    public void onStop(FileAlterationObserver observer) {
        System.out.println("观察文件变化任务停止");
    }
}

